document.querySelector("#btn-login"),addEventListener("click",async function(){
    //发请求 接注册接口
    //     axios({
    //         url:"register",
    //         method:"post",
    //         data:{
    //             username:"dxw",
    //             password:"123456"
    //         }
    //     })
    //收集表单数据
    const form =document.querySelector(".login-form")
    const data = serialize(form,{empty:true,hash:true})
    // console.log(data)
    const{ username,password}=data
    
    //非空验证
    if (username ===''|| password ===''){
        showToast("用户名和密码不能为空!")
        return
    }
    //长度验证
    if(username.length < 8 || username.length<6||password.length>30){
        showToast("太长了太高了!!!8-30位!!!")
        return
    }
    //数据提交
    try{
        //ES6 异步
        const res = await axios.post('/login',{username,password})
        // console.log('res:',res.data):
        showToast(res.data.message)
        //缓存响应数据
        localStorage.setItem('token',res.data.token)
        localStorage.setItem('username',res.data.username)
        setTimeout(()=>{
            location.href="./index.html"
        },1500)
    }
    catch(error){
        showToast(error.response.data.message)
    }
})
    